//
//  DCBaseViewController.m
//  Driver
//
//  Created by 大橙子 on 2018/11/5.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCBaseViewController.h"

@interface DCBaseViewController ()
@property (nonatomic,strong) UIView *bgView;
@end

@implementation DCBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = BackgroundColor;
}
-(void)setUpBgViewIsShow:(BOOL)isShow block:(block)block
{
    if (isShow) {
        [self.view insertSubview:self.bgView atIndex:0];
        self.block = block;
    }else{
        if (self.bgView) {
            [self.bgView removeFromSuperview];
        }
    }
}
-(UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.size = CGSizeMake(self.view.width, 120);
        _bgView.x = 0;
        _bgView.y = 110*HEIGHTSCALE6;
        _bgView.userInteractionEnabled = YES;
        
        UIImageView *imageView = [[UIImageView alloc]initWithImage:IMAGENAME(@"bgImage")];
        imageView.frame = CGRectMake((_bgView.width - 100)/2, 0, 100, 100);
        imageView.userInteractionEnabled = YES;
        [_bgView addSubview:imageView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame), _bgView.width, 20)];
        label.text = @"暂无数据，点击重新加载";
        label.font = FONT(14);
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor lightGrayColor];
        label.userInteractionEnabled = YES;
        [_bgView addSubview:label];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapDidClick)];
        [_bgView addGestureRecognizer:tap];
    }
    return _bgView;
}

-(void)tapDidClick
{
    if (_block) {
        _block();
    }
}
- (UIButton *)buttonWithFrame:(CGRect)frame title:(NSString *)title action:(SEL)action
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundImage:[DCTool getImageForColor:BlueColor] forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    btn.layer.masksToBounds = YES;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.titleLabel.font = FONT(15);
    return btn;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
